<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\admin\service\GlobalConfig;
use app\admin\service\SystemService;
use think\facade\Request;

class Config extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 系统配置
    public function index()
    {
        if (Request::isPost()) {
            GlobalConfig::updateConfig(Request::post('', '', 'strip_tags'));
            return $this->getJson();
        }
        $data = $this->global_config;
        if (!isset($data['file_type'])) {
            $data['file_type'] = 1;
        }
        return $this->fetch('', [
            'data' => $data
        ]);
    }

    public function email()
    {
        if (Request::isAjax()) {
            return $this->getJson(SystemService::sendEmail());
        }
        return $this->fetch();
    }
}
